import axios from '@/utils/request'


// data包括编辑器内容和标题和状态
export const submitArticle = (data) => {
    return axios.post('/articles', data);
  };

export const updateArticle = (data, id) => {
    return axios.put(`/articles/${id}`, data);
};
export const updateArticleStatus = (id, status) => {
    return axios.put(`/articles/status/${id}`, null, {
        params: {
            status
        }
    });
};

export const findArticleById = (id) => {
    return axios.get("/articles/" + id)
}

export const getRecentArticles = (pageNum, pageSize) => {
    return axios.get("/articles", {
        params: {
            pageNum,
            pageSize
        }
    })
}

export const getPublishedArticlesByUserIdOrderByDESC = (userId, pageNum, pageSize) => {
    return axios.get("/articles/user", {
        params: {
            userId,
            pageNum,
            pageSize
        }
    })
}

export const getDraftArticlesByUserIdOrderByDESC = (userId, pageNum, pageSize) => {
    return axios.get("/articles/user/draft", {
        params: {
            userId,
            pageNum,
            pageSize
        }
    })
}
export const getArticlesByUserIdAndKeyWordOrderByDESC = (userId, keyWord, pageNum, pageSize) => {
    return axios.get("/articles/user/key-word", {
        params: {
            userId,
            keyWord,
            pageNum,
            pageSize
        }
    })
}
export const getPublishedArticlesByKeyWordOrderByDESC = (keyWord, pageNum, pageSize) => {
    return axios.get("/articles/search", {
        params: {
            keyWord,
            pageNum,
            pageSize
        }
    });
};
